#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    bool isPalindrome(string s) {
        int left = 0, right = s.size() - 1;
        while (left < right)
        {
            while (left < right && !isalnum(s[left]))
                left++;
            while (left < right && !isalnum(s[right]))
                right--;

            if (isalpha(s[left]) && isalpha(s[right]))
            {
                char s_l = islower(s[left]) ? s[left] : s[left] + 'a' - 'A';
                char s_r = islower(s[right]) ? s[right] : s[right] + 'a' - 'A';

                if (s_l != s_r)
                    return false;
            }
            else
            {
                if (s[left] != s[right])
                    return false;
            }

            left++;
            right--;
        }

        return true;
    }
};